import java.util.Arrays;
import java.util.Scanner;

public class Test {

    public static boolean funjishu(int[]  array){
        int count = 0;
        for (int i = 0; i < array.length; i++) {
            if(array[i] %2 != 0){ //奇数
                count++;
            }else if(array[i] %2 == 0){//偶数
                count = 0;
            }
            if(count == 3)
                return true;
        }
        return false;
    }


    public static void main9(String[] args) {
        //给你一个整数数组 arr，请你判断数组中是否存在连续三个元素都是奇数的情况：如果存在，请返回 true ；否则，返回 false
        int[] arr = {1,2,4,3,6,5,7,4,1};
        boolean n = funjishu(arr);
        System.out.println(n);
    }

    public static int fundMoreNum2(int[] array){
       int count = 0;
       int tmp = array[0];
        for (int i = 0; i < array.length; i++) {
            if(array[i] == tmp){
                count++;
            }else if(array[i] != tmp){
                count--;
            }

            if(count == 0){
                tmp = array[i];
                count++;
            }
        }
        return tmp;
    }
    public static void main8(String[] args) {
        int[] array = {2,2,3,1,2,2,5,8,7};
        int n = fundMoreNum2(array);
        System.out.println(n);
    }

    public static int fundMoreNum(int[] array){
        Arrays.sort(array);
        return array[array.length/2];
    }
    public static void main7(String[] args) {
        int[] array = {2,2,3,1,2,2,5,8,7};
        int n = fundMoreNum(array);
        System.out.println(n);
    }



    public static int funNum(int[] array){
        int ret = array[0];
        for (int i = 1; i < array.length; i++) {
            ret ^= array[i];
        }
        return ret;
    }
    public static void main6(String[] args) {
        int[] array = {10,3,10,20,3};
        int n = funNum(array);
        System.out.println(n);
    }


    public static int[] findTarget(int[] array,int target){
        int[] ret = {-1,-1};
        for (int i = 0; i < array.length; i++) {
            for (int j = i+1; j < array.length; j++) {
                if(array[i]+array[j] == target){
                    ret[0] = i;
                    ret[1] = j;
                    return ret;
                }
            }
        }
        return ret;
    }
    
    public static void main5(String[] args) {
        int[] array = {1,10,3,4,5};
        int[] ret = findTarget(array, 8);
        System.out.println(Arrays.toString(ret));
    }

    public static void bubbleSort(int[] array ){
        //此时最外层控制的就是趟数
        for (int i = 0; i < array.length; i++) {
            boolean flg = false;
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j] >array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flg = true;
                }
            }
            if(flg == false){
                return;
            }
        }
    }
    public static void main4(String[] args) {
        int[] arr = {1,2,75,3,4,5,6,78,12,45,63};
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }




    public static int binarySearch(int [] array,int key){
        int left = 0;
        int right = array.length-1;
        while(left <= right){
            int mid = (left+right)/2;
            if(array[mid] <key){
                left = mid+1;
            }else if(array[mid] >key){
                right = mid-1;
            }else{
                return mid;
            }
        }
        return -1;
    }

    public static void main3(String[] args) {
        //二分查找的前提是，数组必须是有序的
        int[] arr = {1,2,75,3,4,5,6,78,12,45,63};
        Arrays.sort(arr);

        // 自己写的
        int n = binarySearch(arr,6);
        System.out.println(n);

        //系统自带的
        //System.out.println(Arrays.binarySearch(arr, 12));
    }
    public static void  change(int[] arr){
        int left = 0;
        int right = arr.length-1;
        while(left<right){
            while(left<right && arr[left]%2 !=0){
                left++;
            }
            while(left<right && arr[right]%2 == 0){
                right--;
            }
            int tmp = arr[left];
            arr[left] = arr[right];
            arr[right] = tmp;
        }
    }

    public static void main2(String[] args) {
        int[] arr = {1,2,3,4,5,6};
        change(arr);
        System.out.println(Arrays.toString(arr));
    }



    static int[] transform(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            arr[i] = arr[i]*2;
        }
        return arr;
    }
    public static void main1(String[] args) {
        //1.实现一个方法 transform, 以数组为参数, 循环将数组中的每个元素 乘以 2 , 并设置到对应的数组元素上. 例如 原数组为 {1, 2, 3}, 修改之后为 {2, 4, 6}
        int[] arr = {1,2,3,4,5};
        int[]  arr1 = transform(arr);
        System.out.println(Arrays.toString(arr1));
    }

}
